import threading

num = 1
local = threading.local()


def run(x, y):
    print("子线程%s初始x = %d" % (threading.current_thread().name, x))
    for i in range(100000):
        x = x + y
    print("子线程%s结束x = %d" % (threading.current_thread().name, x))


def run1(n):
    print("子线程开始%s" % threading.current_thread().name)
    local.x = num    # 不同的线程引用相同的全局变量
    run(local.x, n)
    print("子线程结束%s" % threading.current_thread().name)


if __name__ == "__main__":
    t1 = threading.Thread(target=run1, args=(6, ))
    t2 = threading.Thread(target=run1, args=(9, ))
    t1.start()
    t2.start()
    print("num = ", num)










